package com.tigercel.xiangchengyun.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.tigercel.xiangchengyun.utils.Util;

import java.util.List;

public class NewsPagerAdapter extends FragmentStatePagerAdapter {
    private List<String> mTitles;
    private List<? extends Fragment> mFragments;
    public NewsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public NewsPagerAdapter(FragmentManager fm, List<String> mTitles, List<? extends Fragment> fragments) {
        super(fm);
        this.mTitles = mTitles;
        this.mFragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mTitles.size()==mFragments.size()?mFragments.size():0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return !Util.isNullOrEmpty(mTitles) ? mTitles.get(position) : "";
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
